/**
 * 
 */
package com.cats.adapter;

import java.util.ArrayList;
import com.cats.R;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

/**
 * @author Jason
 *
 */
public class MemberAdapter extends ArrayAdapter<String> {

	    Context context;
	    int layoutResourceId;
	    ArrayList<String> datas = null;

		public MemberAdapter(Context context, int resourceId, ArrayList<String> objects) {
			super(context, resourceId, objects);
	        this.layoutResourceId = resourceId;
	        this.context = context;
	        this.datas = (ArrayList<String>) objects;
	        System.out.println("[MemberAdapter]datas count:" + this.datas.size());
	    }

	    @Override
	    public View getView(int position, View convertView, ViewGroup parent) {
	        View row = convertView;
	        MemberHolder holder = null;
	       
	        if(row == null)
	        {
	            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
	            row = inflater.inflate(layoutResourceId, parent, false);
	           
	            holder = new MemberHolder();
	            holder.itemNameTextView = (TextView)row.findViewById(R.id.itemName);
	           
	            row.setTag(holder);
	        }
	        else
	        {
	            holder = (MemberHolder)row.getTag();
	        }
	       
	        holder.itemNameTextView.setText(this.datas.get(position));
	        
	        System.out.println("[MemberAdapter]getView()");
	       
	        return row;
	    }
	   
	    static class MemberHolder
	    {
	        TextView itemNameTextView;
	    }
}
